package com.wuliupai.delivery.wuliupaidelivery.activity;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.mapapi.utils.OpenClientUtil;
import com.umeng.message.PushAgent;
import com.wuliupai.delivery.wuliupaidelivery.App;
import com.wuliupai.delivery.wuliupaidelivery.R;
import com.wuliupai.delivery.wuliupaidelivery.constants.CommConstants;
import com.wuliupai.delivery.wuliupaidelivery.constants.Value;
import com.wuliupai.delivery.wuliupaidelivery.net.NetConn;
import com.wuliupai.delivery.wuliupaidelivery.net.NetResultOperate;
import com.wuliupai.delivery.wuliupaidelivery.ui.MyToolbar;
import com.wuliupai.delivery.wuliupaidelivery.ui.RefreshAndLoadLayout;
import com.wuliupai.delivery.wuliupaidelivery.utils.ActivityCollector;
import com.wuliupai.delivery.wuliupaidelivery.utils.AnimUtils;
import com.wuliupai.delivery.wuliupaidelivery.utils.LogUtils;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.json.JSONObject;

import java.util.Map;

import cn.bingoogolapple.qrcode.core.BGAQRCodeUtil;
import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder;
import cn.bingoogolapple.refreshlayout.BGAMeiTuanRefreshViewHolder;
import cn.bingoogolapple.refreshlayout.BGARefreshLayout;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Descriptions：项目的BaseActivity
 * <p>
 * Author：ChenME
 * Date：11/10/2016
 * Email：ibelieve1210@163.com
 */
@EActivity
public class AppBaseActivity extends AppCompatActivity {

    @Bean(AnimUtils.class)
    AnimUtils animUtils;

    private NetConn netConn;//网络请求

    private ProgressDialog progressDialog;//进度对话框
    private RelativeLayout mLl_common_data_type;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        netConn = new NetConn();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // 禁用横屏
        ActivityCollector.addActivity(this);
        PushAgent.getInstance(AppBaseActivity.this).onAppStart();
//        String contextString = this.toString();
//        String substring = contextString.substring(contextString.lastIndexOf(".") + 1, contextString.indexOf("@"));
//        LogUtils.log("当前界面：" + substring);
    }


    /**
     * 设置默认的标题栏
     *
     * @param activity 调用的Activity的实例
     * @param title    标题字符串
     */
    protected void setDefaultTitle(Activity activity, String title) {
        setTitle(activity, title, R.drawable.comm_press_return_selector, true, null);
    }

    /**
     * 设置默认的标题栏
     *
     * @param activity 调用的Activity的实例
     * @param titleRes 标题资源ID
     */
    protected void setDefaultTitle(Activity activity, int titleRes) {
        setDefaultTitle(activity, getString(titleRes));
    }

    /**
     * 设置标题栏
     *
     * @param activity                      调用的Activity的实例
     * @param titleRes                      标题的资源ID
     * @param navigationIconRes             左侧按钮的图标
     * @param isTitleInMiddle               是否将标题居中
     * @param mOnNavigationBtnClickListener 左侧按钮的点击事件（如果为空，则为默认，Action：退出，Anim：左右切换）
     */
    protected void setTitle(Activity activity, int titleRes, int navigationIconRes, boolean isTitleInMiddle, OnNavigationBtnClickListener mOnNavigationBtnClickListener) {
        setTitle(activity, getString(titleRes), navigationIconRes, isTitleInMiddle, mOnNavigationBtnClickListener);
    }

    /**
     * 设置标题栏
     *
     * @param activity                      调用的Activity的实例
     * @param title                         标题字符串
     * @param navigationIconRes             左侧按钮的图标
     * @param isTitleInMiddle               是否将标题居中
     * @param mOnNavigationBtnClickListener 左侧按钮的点击事件（如果为空，则为默认，Action：退出，Anim：左右切换）
     */
    protected void setTitle(Activity activity, String title, int navigationIconRes, boolean isTitleInMiddle,
                            OnNavigationBtnClickListener mOnNavigationBtnClickListener) {

        MyToolbar toolbar = (MyToolbar) findViewById(R.id.toolbar);
        toolbar.setTitleInCenter(isTitleInMiddle);
        toolbar.setTitle(title);
        toolbar.setNavigationIcon(navigationIconRes);

        /**
         * 注意：
         * 1. setTitle()方法必须放在setSupportActionBar()方法之前；
         * 2. 所有的事件监听器必须放在setSupportActionBar()方法之后；
         */
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mOnNavigationBtnClickListener) {
                    mOnNavigationBtnClickListener.navigationClick();
                } else {
                    finish();
                    animUtils.leftOutAnimation(activity);
                }
            }
        });

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (null != mOnNavigationBtnClickListener) {
                    mOnNavigationBtnClickListener.menuItemClick(item);
                    return true;
                } else {
                    return false;
                }
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.findItem(R.id.menuItem1).setVisible(false);
        menu.findItem(R.id.menuItem2).setVisible(false);
        return super.onPrepareOptionsMenu(menu);
    }

    /**
     * 网络访问(无进度对话框)
     *
     * @param context          Context
     * @param netUrl           接口名
     * @param paramInfo        加密后的参数
     * @param netResultOperate 请求结果的回调接口
     */
    protected void callNetWithoutProgressDialog(Context context, String netUrl, String paramInfo,
                                                NetResultOperate netResultOperate) {
        callNet(context, netUrl, paramInfo, "", netResultOperate);
    }

    /**
     * 网络访问
     *
     * @param context          Context
     * @param netUrl           接口名
     * @param paramInfo        加密后的参数
     * @param netResultOperate 请求结果的回调接口
     */
    public void callNet(Context context, String netUrl, String paramInfo, NetResultOperate netResultOperate) {
        callNet(context, netUrl, paramInfo, context.getString(R.string.string_netLoading_loading), netResultOperate);
    }

    /**
     * 网络访问
     *
     * @param context                 Context
     * @param netUrl                  接口名
     * @param paramInfo               加密后的参数
     * @param progressDialogHintResID 对话框提示文字的资源ID
     * @param netResultOperate        请求结果的回调接口
     */
    protected void callNet(Context context, String netUrl, String paramInfo, int progressDialogHintResID, NetResultOperate netResultOperate) {
        callNet(context, netUrl, paramInfo, context.getString(progressDialogHintResID), netResultOperate);
    }


    /**
     * 网络访问
     *
     * @param context            Context
     * @param netUrl             接口名
     * @param paramInfo          加密后的参数
     * @param progressDialogHint 对话框提示文字
     * @param netResultOperate   请求结果的回调接口
     */
    protected void callNet(Context context, String netUrl, String paramInfo, String progressDialogHint, NetResultOperate netResultOperate) {
        if (null == progressDialog) {
            progressDialog = new ProgressDialog(context);
        }
        LogUtils.log("地址---" + Value.PATH_SERVER + netUrl);
        progressDialog.setMessage(progressDialogHint);
        progressDialog.show();
        netConn.call(Value.PATH_SERVER + netUrl, paramInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        dismissProgressDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        dismissProgressDialog();
                        netResultOperate.onErr(NetResultOperate.CUSTOM_STATE_NET_ERROR,
                                context.getString(R.string.string_commonNetErrDialogTips), context);
                    }

                    @Override
                    public void onNext(String netContent) {
                        if (netContent != null) {
                            LogUtils.log("返回数据~~~： " + netContent);

                            String code = null;
                            String errorCode = null;
                            JSONObject result = null;

                            try {
                                JSONObject jsonObject = new JSONObject(netContent);
                                code = jsonObject.getString("code");
                                errorCode = jsonObject.getString("errorCode");
                                result = jsonObject.getJSONObject("result");
                            } catch (Exception e) {
                                e.printStackTrace();
                                result = null;
                            }

                            try {
                                switch (code) {
                                    case NetResultOperate.STATE_SUCCESS://数据请求成功
                                        if (null != result) {
                                            netResultOperate.onSuccess(result.toString());
                                        } else {
                                            netResultOperate.onSuccess("");
                                        }

                                        if (mLl_common_data_type != null) {
                                            mLl_common_data_type.setVisibility(View.GONE);
                                        }
                                        break;

                                    case NetResultOperate.STATE_LOGIN_AT_OTHER_DEVICE://账号已经在其他设备登陆
                                    case NetResultOperate.STATE_LOGIN_EXPIRED://登陆超时
                                    case NetResultOperate.STATE_LOGIN_EXPIRED2://太久没有登陆过
                                        //TODO 重新登录
                                        new AlertDialog.Builder(AppBaseActivity.this)
                                                .setTitle("数据异常")
                                                .setMessage(errorCode)
                                                .setPositiveButton("确定", (dialog, which) -> {
                                                    Intent intent = new Intent(AppBaseActivity.this, LoginActivity_.class);
                                                    startActivity(intent);
                                                    dialog.dismiss();
                                                    ActivityCollector.finishAll();
                                                }).show();
                                        break;

                                    case NetResultOperate.STATE_DATA_EMPTY://数据为空
                                        netResultOperate.onDataEmpty(errorCode);
                                        break;

                                    case NetResultOperate.STATE_DATA_END://数据已经到结尾
                                        netResultOperate.onDataEnd(errorCode);
                                        break;

                                    default://其他情况下的登陆错误回调给子类处理
                                        netResultOperate.onErr(code, errorCode, context);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    }

    /**
     * 网络访问
     *
     * @param context            Context
     * @param netUrl             接口名
     * @param params             参数map
     * @param progressDialogHint 对话框提示文字
     * @param netResultOperate   请求结果的回调接口
     */
    protected void callNet(Context context, String netUrl, Map<String, Object> params, String progressDialogHint, NetResultOperate netResultOperate) {
        if (null == progressDialog) {
            progressDialog = new ProgressDialog(context);
        }
        LogUtils.log("地址---" + Value.PATH_SERVER + netUrl);
        progressDialog.setMessage(progressDialogHint);
        progressDialog.show();
        netConn.uplaodFiles(Value.PATH_SERVER + netUrl, params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        dismissProgressDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        dismissProgressDialog();
                        netResultOperate.onErr(NetResultOperate.CUSTOM_STATE_NET_ERROR,
                                context.getString(R.string.string_commonNetErrDialogTips), context);
                    }

                    @Override
                    public void onNext(String netContent) {
                        if (netContent != null) {
                            LogUtils.log("返回数据~~~： " + netContent);

                            String code = null;
                            String errorCode = null;
                            JSONObject result = null;

                            try {
                                JSONObject jsonObject = new JSONObject(netContent);
                                code = jsonObject.getString("code");
                                errorCode = jsonObject.getString("errorCode");
                                result = jsonObject.getJSONObject("result");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            try {
                                switch (code) {
                                    case NetResultOperate.STATE_SUCCESS://数据请求成功
                                        if (null != result) {
                                            netResultOperate.onSuccess(result.toString());
                                        } else {
                                            netResultOperate.onSuccess("");
                                        }

                                        if (mLl_common_data_type != null) {
                                            mLl_common_data_type.setVisibility(View.GONE);
                                        }
                                        break;

                                    case NetResultOperate.STATE_LOGIN_AT_OTHER_DEVICE://账号已经在其他设备登陆
                                    case NetResultOperate.STATE_LOGIN_EXPIRED://登陆超时
                                    case NetResultOperate.STATE_LOGIN_EXPIRED2://太久没有登陆过
                                        //TODO 重新登录
                                        break;

                                    case NetResultOperate.STATE_DATA_EMPTY://数据为空
                                        netResultOperate.onDataEmpty(errorCode);
                                        break;

                                    case NetResultOperate.STATE_DATA_END://数据已经到结尾
                                        netResultOperate.onDataEnd(errorCode);
                                        break;

                                    default://其他情况下的登陆错误回调给子类处理
                                        netResultOperate.onErr(code, errorCode, context);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    }


    public void initRefreshView(Context context, BGARefreshLayout refreshLayout, boolean isPullDownRefresh, boolean isLoadingMore) {
        BGAMeiTuanRefreshViewHolder meiTuanViewHolder = new BGAMeiTuanRefreshViewHolder(context, isLoadingMore);
        meiTuanViewHolder.setRefreshingAnimResId(R.drawable.anim_loading);
        meiTuanViewHolder.setPullDownImageResource(R.mipmap.refresh_1);
        meiTuanViewHolder.setChangeToReleaseRefreshAnimResId(R.drawable.anim_loading);
        refreshLayout.setRefreshViewHolder(meiTuanViewHolder);
        refreshLayout.setIsShowLoadingMoreView(isLoadingMore);
        refreshLayout.setPullDownRefreshEnable(isPullDownRefresh);
    }


    private void dismissProgressDialog() {
        if (null != progressDialog) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }


    /**
     * 设置界面 数据为空 加载失败界面
     * (showType) 显示界面类型
     */
    public void setCommenActivtiyType(int showType, OnRefreshBtnClickListener mOnRefreshBtnClickListener) {
        mLl_common_data_type = (RelativeLayout) findViewById(R.id.ll_common_data_type);
        TextView tv_common_data_type = (TextView) findViewById(R.id.tv_common_data_type);
        ImageView iv_common_data_type = (ImageView) findViewById(R.id.iv_common_data_type);
        Button btn_common_data_type = (Button) findViewById(R.id.btn_common_data_type);
        mLl_common_data_type.setVisibility(View.VISIBLE);
        switch (showType) {
            case CommConstants.TYPE_EMPTY: //当界面为空
                tv_common_data_type.setText(getResources().getString(R.string.string_common_type_empty));
                iv_common_data_type.setImageResource(R.mipmap.type_empty);
                break;
            case CommConstants.TYPE_ERROR: //当数据加载失败
                tv_common_data_type.setText(getResources().getString(R.string.string_common_type_eorror));
                iv_common_data_type.setImageResource(R.mipmap.type_error);
                break;
            case CommConstants.TYPE_HIDE: //当数据已经加载 隐藏数据为空界面
                mLl_common_data_type.setVisibility(View.GONE);
                break;
        }

        btn_common_data_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnRefreshBtnClickListener != null) {
                    mOnRefreshBtnClickListener.refreshClick();
                }
            }
        });
    }

    /**
     * 提示未安装百度地图app或app版本过低
     */
    public void showBaiduMapErrDialog(Activity activity) {
        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);
        builder.setMessage("您尚未安装百度地图app或app版本过低，点击确认安装？");
        builder.setTitle("提示");
        builder.setPositiveButton("确认", (dialog, which) -> {
            dialog.dismiss();
            OpenClientUtil.getLatestBaiduMapApp(activity);
        });

        builder.setNegativeButton("取消", (dialog, which) -> dialog.dismiss());
        builder.create().show();
    }

    /**
     * 当界面为空 刷新界面数据按钮
     */
    interface OnRefreshBtnClickListener {
        void refreshClick();
    }


    interface OnNavigationBtnClickListener {
        void navigationClick();

        void menuItemClick(MenuItem item);
    }


    /**
     * 取消广播的注册
     *
     * @param lbm
     * @param receiver
     */
    public void unregisterMyReceiver(LocalBroadcastManager lbm, BroadcastReceiver receiver) {
        if (null != lbm && null != receiver) {
            lbm.unregisterReceiver(receiver);
        }
    }

    /**
     * 显示Common对话框
     *
     * @param title                           标题
     * @param leftBtnText                     左边按钮文字
     * @param rightBtnText                    右边按钮文字
     * @param isShowRightBtn                  是否显示右边文字
     * @param mOnCommonDialogBtnClickListener Common对话框的回调接口
     */
    protected void showCommonDialog(String title, String leftBtnText, String rightBtnText, boolean isShowRightBtn, OnCommonDialogBtnClickListener mOnCommonDialogBtnClickListener) {
        Dialog view = new Dialog(this, R.style.DialogFullWindowStyle);// 创建自定义样式dialog

        view.setCancelable(false);// 不可以用“返回键”取消
        view.setContentView(R.layout.dialog_common);// 设置布局

        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
        TextView tv_leftBtn = (TextView) view.findViewById(R.id.tv_leftBtn);

        tv_title.setText(title);

        tv_leftBtn.setText(leftBtnText);

        if (null != tv_content) {
            mOnCommonDialogBtnClickListener.setContentText(tv_content);
        }

        tv_leftBtn.setOnClickListener(v -> {
            if (null != mOnCommonDialogBtnClickListener) {
                mOnCommonDialogBtnClickListener.onLeftBtnClick(view);
            }
            view.dismiss();
        });
        if (isShowRightBtn) {
            view.findViewById(R.id.view_divider).setVisibility(View.VISIBLE);
            TextView tv_rightBtn = (TextView) view.findViewById(R.id.tv_rightBtn);
            tv_rightBtn.setVisibility(View.VISIBLE);
            tv_rightBtn.setText(rightBtnText);
            tv_rightBtn.setOnClickListener(v -> {
                if (null != mOnCommonDialogBtnClickListener) {
                    mOnCommonDialogBtnClickListener.onRightBtnClick(view);
                }
                view.dismiss();
            });
        }

        view.show();
    }

//    private void copyText2Clipboard(TextView textView, boolean isStart) {
//        ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
//        mClipboardManager.setText(textView.getText());
//        String toast = isStart ? "发货地址已复制成功！" : "成功复制收货地址！";
//        App.toast(toast);
//    }

    /**
     * 拨打电话
     *
     * @param phoneNum 电话号码
     */
    public void callPhone(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        startActivity(intent);
    }

    /**
     * 显示二维码
     */
    protected void showQRCodeDialog(Activity activity, String qrCode, String contentTop, String contentBottom,OnQRCodeClickListener mOnQRCodeClickListener) {
        Observable.create(new Observable.OnSubscribe<Bitmap>() {
            @Override
            public void call(Subscriber<? super Bitmap> subscriber) {
                Bitmap logoBitmap = BitmapFactory.decodeResource(activity.getResources(),
                        R.mipmap.ic_launcher);
                Bitmap bitmap = QRCodeEncoder.syncEncodeQRCode(qrCode, BGAQRCodeUtil.dp2px(activity, activity.getResources().getDimension(R.dimen.size_taskDetail_taskQrCode)), Color.BLACK, Color.TRANSPARENT, logoBitmap);
                if (null == bitmap) {
                    subscriber.onError(new Throwable(activity.getString(R.string.string_taskChangeTipDialog_tipsErrQRCode)));
                    LogUtils.log("生成二维码失败~~~");
                } else {
                    subscriber.onNext(bitmap);
                }
                subscriber.onCompleted();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Bitmap>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        App.toast(R.string.string_taskChangeTipDialog_tipsErrQRCode);
                    }

                    @Override
                    public void onNext(Bitmap bitmap) {

                        Dialog view = new Dialog(activity, R.style.DialogFullWindowStyle);// 创建自定义样式dialog

                        view.setCancelable(false);// 不可以用“返回键”取消
                        view.setContentView(R.layout.dialog_show_qrcode);// 设置布局

                        TextView tv_tips1 = (TextView) view.findViewById(R.id.tv_tips1);
                        TextView tv_tips2 = (TextView) view.findViewById(R.id.tv_tips2);

                        tv_tips1.setText(contentTop);
                        tv_tips2.setText(contentBottom);

                        ImageView iv_qrcode = (ImageView) view.findViewById(R.id.iv_qrcode);

                        iv_qrcode.setImageBitmap(bitmap);

                        iv_qrcode.setOnLongClickListener(new View.OnLongClickListener() {
                            @Override
                            public boolean onLongClick(View v) {
                                if(null!=mOnQRCodeClickListener){
                                    mOnQRCodeClickListener.onQRCodeLongClick(view);
                                    return true;
                                }
                                return false;
                            }
                        });

//                        iv_qrcode.setOnLongClickListener(new View.OnLongClickListener() {
//                            @Override
//                            public boolean onLongClick(View v) {
//                                ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
//                                mClipboardManager.setText(qrCode);
//                                App.toast(R.string.string_taskChangeTipDialog_tipsToast);
//                                view.dismiss();
//                                return true;
//                            }
//                        });

                        view.findViewById(R.id.ivBtn_closeDialog).setOnClickListener(v ->
                                view.dismiss());
                        view.show();
                    }
                });
    }

    public void clearRefresh(RefreshAndLoadLayout swipeLayout, boolean isClear) {
        if (null != swipeLayout) {
            if (isClear) {
                swipeLayout.setRefreshing(false);
            } else {
                swipeLayout.setLoading(false);
            }
        }
    }


//    protected void showQRCodeDialog(Activity activity, String qrCode) {
//        Observable.create(new Observable.OnSubscribe<Bitmap>() {
//            @Override
//            public void call(Subscriber<? super Bitmap> subscriber) {
//                Bitmap logoBitmap = BitmapFactory.decodeResource(activity.getResources(),
//                        R.mipmap.ic_launcher);
//                Bitmap bitmap = QRCodeEncoder.syncEncodeQRCode(qrCode, BGAQRCodeUtil.dp2px(activity, activity.getResources().getDimension(R.dimen.size_taskDetail_taskQrCode)), Color.BLACK, Color.TRANSPARENT, logoBitmap);
//                if (null == bitmap) {
//                    subscriber.onError(new Throwable(activity.getString(R.string.string_taskChangeTipDialog_tipsErrQRCode)));
//                    LogUtils.log("生成二维码失败~~~");
//                } else {
//                    subscriber.onNext(bitmap);
//                }
//                subscriber.onCompleted();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<Bitmap>() {
//                    @Override
//                    public void onCompleted() {
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        App.toast(R.string.string_taskChangeTipDialog_tipsErrQRCode);
//                    }
//
//                    @Override
//                    public void onNext(Bitmap bitmap) {
//
//                        Dialog view = new Dialog(activity, R.style.DialogFullWindowStyle);// 创建自定义样式dialog
//
//                        view.setCancelable(false);// 不可以用“返回键”取消
//                        view.setContentView(R.layout.dialog_show_qrcode);// 设置布局
//
//                        ImageView iv_qrcode = (ImageView) view.findViewById(R.id.iv_qrcode);
//
//                        iv_qrcode.setImageBitmap(bitmap);
//                        iv_qrcode.setOnLongClickListener(new View.OnLongClickListener() {
//                            @Override
//                            public boolean onLongClick(View v) {
//                                ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
//                                mClipboardManager.setText(qrCode);
//                                App.toast(R.string.string_taskChangeTipDialog_tipsToast);
//                                view.dismiss();
//                                return true;
//                            }
//                        });
//
//                        view.findViewById(R.id.ivBtn_closeDialog).setOnClickListener(v ->
//                                view.dismiss());
//                        view.show();
//                    }
//                });
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
    }

    /**
     * Common对话框的回调接口
     */
    interface OnCommonDialogBtnClickListener {
        // 显示内容的 TextView，不直接赋值，而是把 TextView 回调回去，其目的是方便 TextView 在 setText() 时可以传入多种类型的数据
        void setContentText(TextView tv_content);

        void onLeftBtnClick(Dialog dialog);

        void onRightBtnClick(Dialog dialog);
    }

    /**
     * 二维码对话框中二维码的点击事件
     */
    interface OnQRCodeClickListener {
        void onQRCodeClick(Dialog dialog);

        void onQRCodeLongClick(Dialog dialog);
    }
}